package com.yshkj.payment.dto;

import com.yshkj.payment.entity.medicinal.Medicinal;
import com.yshkj.payment.entity.medicinal.Producer;
import com.yshkj.payment.entity.medicinal.Spec;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 唐旭 on 2016/10/5.
 */
@Data
public class MedicinalFormDto extends JsonBaseDto {
    private String uuid;
    private String name;
    private boolean newProducer = false;
    private List<ProducerDto> producerList = new ArrayList<>();
    //如果传入uuid,则有可能是重新选择了厂商
    //如果没有传入uuid,则是新建厂商
    private ProducerDto producer;
    private List<SpecDto> specList = new ArrayList<>();

    public MedicinalFormDto() {
    }

    public MedicinalFormDto(Medicinal medicinal) {
        this.uuid = medicinal.getUuid();
        this.name = medicinal.getName();
        Producer producer = medicinal.getProducer();
        if (producer != null) {
            this.producer = new ProducerDto(producer);
        }
        for (Spec spec : medicinal.getSpecList()) {
            specList.add(new SpecDto(spec));
        }
    }

    public void update(Medicinal medicinal) {
        medicinal.setName(this.getName());
    }
}
